package cn.com.roy.thread.t4_1_14.awaituninterruptiblytest1;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class Myservice {
    public ReentrantLock lock = new ReentrantLock();
    private Condition condition = lock.newCondition();

    public void testMethod(){
        try {
            lock.lock();
            System.out.println("wait begin " + Thread.currentThread().getName() );
            //condition.await();
            condition.awaitUninterruptibly(); // 在进入此方法是设置了当前线程的中断状态，或则在等待时线程被中断，在接受到信号
                                                //那么在接收到信号之前它将继续等待，并且等方法返回之后仍将设置其中断状态
            System.out.println("wait end " + Thread.currentThread().getName());
        } catch (Exception e){
            e.printStackTrace();
        }finally {
            if(lock.isHeldByCurrentThread()){
                lock.unlock();
            }
        }
    }
}
